<template>
  <div>
    <div style="margin: 10px 0">
      <el-input
        style="width: 200px"
        placeholder="请输入活动名称"
        suffix-icon="el-icon-search"
        v-model="username"
      ></el-input>
      <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
      <el-button type="warning" @click="reset">重置</el-button>
    </div>
    <el-table
      :data="tableData"
      border
      stripe
      :header-cell-class-name="'headerBg'"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="id" label="ID" width="80"></el-table-column>
      <el-table-column
        prop="activityName"
        label="活动名称"
        width="140"
      ></el-table-column>
      <el-table-column prop="activityArea" label="活动地址"> </el-table-column>
      <el-table-column
        prop="activityScale"
        label="活动规模"
        width="120"
      ></el-table-column>
      <el-table-column prop="activityTime" label="活动时间"></el-table-column>
      <el-table-column prop="status" label="活动状态">
        <template slot-scope="scope">
          <el-tag type="primary" v-if="scope.row.status === 0">未审核</el-tag>
          <el-tag type="warning" v-if="scope.row.status === 1">审核通过</el-tag>
          <el-tag type="danger" v-if="scope.row.status === 2"
            >审核不通过</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column prop="campusName" label="社团名称"></el-table-column>
      <el-table-column prop="createTime" label="创建时间"></el-table-column>
      <el-table-column prop="moneyStatus" label="资金操作"  width="200" align="center" v-if="user.role === 'ROLE_MASTER'">
        <template slot-scope="scope">
          <el-popconfirm
              class="ml-5"
              confirm-button-text='确定'
              cancel-button-text='我再想想'
              icon="el-icon-info"
              icon-color="red"
              title="您确定申请资金吗？"
              @confirm="money(scope.row.id)"
          >
            <el-button type="primary" slot="reference" v-if="scope.row.status === 1 && scope.row.moneyStatus === 0 ">资金申请<i class="el-icon-remove-outline"></i></el-button>
          </el-popconfirm>
          <el-tag type="primary" v-if="scope.row.status === 1 && scope.row.moneyStatus === -1">资金审核中</el-tag>
          <el-tag type="primary" v-if="scope.row.status === 1 && scope.row.moneyStatus === 1">资金审核通过</el-tag>
          <el-tag type="primary" v-if="scope.row.status === 1 && scope.row.moneyStatus === 2">资金审核不通过</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <div style="padding: 10px 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[2, 5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { serverIp } from "../../../public/config";

export default {
  name: "User",
  data() {
    return {
      user: localStorage.getItem("user")
        ? JSON.parse(localStorage.getItem("user"))
        : {},
      serverIp: serverIp,
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 10,
      activityName: "",
      form: {},
      multipleSelection: [],
    };
  },
  created() {

    this.load();
  },
  methods: {
    load() {
      this.request
        .get("/act/myActivity", {
          params: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            activityName: this.activityName,
            uid: this.user.id,
          },
        })
        .then((res) => {
          this.tableData = res.data.records;
          this.total = res.data.total;
          console.log("++++"+this.user.role)
        });
    },
    money(aid){
        this.$router.push({path: '/master/money',query:{index:aid}})
    },
    handleSelectionChange(val) {
      console.log(val);
      this.multipleSelection = val;
    },
    reset() {
      this.activityName = "";
      this.load();
    },
    handleSizeChange(pageSize) {
      console.log(pageSize);
      this.pageSize = pageSize;
      this.load();
    },
    handleCurrentChange(pageNum) {
      console.log(pageNum);
      this.pageNum = pageNum;
      this.load();
    },
  },
};
</script>


<style>
.headerBg {
  background: #eee !important;
}
</style>
